﻿/****************
 * Copyright 2016 Brian Tabone
 * Licensed under the Apache 2.0 License
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * PhysicsPropertiesInitializer.cs
 * Setup the initial physics properties (such as world geometry, gravity, day period, etc
 * All unites are metric, all time is UTC
 * 10/16/2016
 */

using System.Globalization;
using IAO.Common.ServiceFramework;
using IAO.Common.ServiceFramework.RuntimeProperties;

namespace World3D.PropertyInitalizers
{
    /// <summary>
    ///     Setup the physical world propertie
    /// </summary>
    public class PhysicsPropertiesInitializer
    {
        // Constant properties
        public const float WidthInMeters = 100;
        public const float DepthInMeters = 100;
        public const float HeightInMeters = 100;
        public const float GravitationalAcceleration = 9.81F; // M/S
        public const string PropertyClass = "Physics";
        public const int StartingPropertyID = 6;

        private static int _currentPropertyId; // Set this to the starting property ID

        /// <summary>
        ///     Initialize properties on the specified property manager
        /// </summary>
        /// <param name="manager"></param>
        public static void InitializeOnManager(PropertyManager manager)
        {
            // Set the current property ID to the starting ID, if someone accidentally calls us twice, we wont end up accidentally adding another set of propertys starting from the 
            // last time we were called
            _currentPropertyId = StartingPropertyID;

            manager.AddPersistentPropertyIfNotExists(new Property(GetNextPropertyID(), PropertyClass,
                nameof(WidthInMeters), WidthInMeters.ToString(CultureInfo.InvariantCulture),
                typeof(float).ToString(), true));
            manager.AddPersistentPropertyIfNotExists(new Property(GetNextPropertyID(), PropertyClass,
                nameof(DepthInMeters), DepthInMeters.ToString(CultureInfo.InvariantCulture),
                typeof(float).ToString(), true));
            manager.AddPersistentPropertyIfNotExists(new Property(GetNextPropertyID(), PropertyClass,
                nameof(HeightInMeters), HeightInMeters.ToString(CultureInfo.InvariantCulture),
                typeof(float).ToString(), true));
            manager.AddPersistentPropertyIfNotExists(new Property(GetNextPropertyID(), PropertyClass,
                nameof(GravitationalAcceleration), GravitationalAcceleration.ToString(CultureInfo.InvariantCulture),
                typeof(float).ToString(), true));
        }

        /// <summary>
        ///     Get the property ID to use, this starts the count
        /// </summary>
        /// <returns></returns>
        private static int GetNextPropertyID()
        {
            return _currentPropertyId++;
        }
    }
}